package cn.stylefeng.guns.modular.storage.service.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.storage.entity.StorageOut;
import cn.stylefeng.guns.modular.storage.mapper.StorageOutMapper;
import cn.stylefeng.guns.modular.storage.model.params.StorageOutParam;
import cn.stylefeng.guns.modular.storage.model.result.StorageOutResult;
import  cn.stylefeng.guns.modular.storage.service.StorageOutService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 拣货单表 服务实现类
 */
@Service
public class StorageOutServiceImpl extends ServiceImpl<StorageOutMapper, StorageOut> implements StorageOutService {

    @Override
    public void add(StorageOutParam param){
        StorageOut entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StorageOutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StorageOutParam param){
        StorageOut oldEntity = getOldEntity(param);
        StorageOut newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StorageOutResult findBySpec(StorageOutParam param){
        return this.baseMapper.findBySpec(param);
    }


    @Override
    public List<StorageOutResult> findListBySpec(StorageOutParam param,Long deptId){
        return this.baseMapper.findListBySpec(param,deptId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(StorageOutParam param,String condition,Long deptId,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,deptId, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<StorageOutResult> findPageBySpecNew(StorageOutParam param,String condition,Long deptId){
    	return this.baseMapper.findPageBySpecNew( param,condition,deptId);
    }

    /**
     * 查询工人拣货单地址列表
     * @param param
     * @param condition
     * @param deptId
     * @return
     */
    @Override
    public LayuiPageInfo findPageBySpecWork(StorageOutParam param,String condition,Long deptId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListWork(pageContext, param,condition,deptId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StorageOutParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StorageOut getOldEntity(StorageOutParam param) {
        return this.getById(getKey(param));
    }

    private StorageOut getEntity(StorageOutParam param) {
        StorageOut entity = new StorageOut();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Override
    public StorageOut findLastOne() {
        return this.baseMapper.findLastOne();
    }

	@Override
	public LayuiPageInfo findPageByGet(StorageOutParam storageOutParam, String condition, Long deptId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageByGet(pageContext, storageOutParam,condition,deptId);
        return LayuiPageFactory.createPageInfo(page);
	}

    /**
     * app通过地址id 收货单位id 查询订单列表
     * @return
     */
    @Override
    public  List<StorageOutResult> findPageByGetApp(StorageOutParam storageOutParam, Long deptId){
        return this.baseMapper.findPageByGetApp(storageOutParam,deptId);
    }

    /**
     * app出库审核通过地址id 收货单位id 查询订单列表
     * @return
     */
    @Override
    public  List<StorageOutResult> findPageByGetReview(StorageOutParam storageOutParam, Long deptId){
        return this.baseMapper.findPageByGetReview(storageOutParam,deptId);

    }

    /**
     * app工人通过地址id 收货单位id 查询订单列表
     * @return
     */
    @Override
    public  List<StorageOutResult> findPageByGetAppWork(StorageOutParam storageOutParam, Long deptId,Long operateId){
        return this.baseMapper.findPageByGetAppWork(storageOutParam,deptId,operateId);
    }

    /**
     *  审核查询地址信息。
     * @param param
     * @param deptId
     * @return
     */
    @Override
    public LayuiPageInfo findPageBySpecReview(StorageOutParam param,Long deptId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageBySpecReview(pageContext, param,deptId);
        return LayuiPageFactory.createPageInfo(page);
    }

	@Override
	public LayuiPageInfo querylistPageBySpec(StorageOutParam param, String condition, Long deptId,Long outCustomerId,String singleOutTime
			,Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.querylistPageBySpec(pageContext, param,condition,deptId,outCustomerId,singleOutTime
        		, operateId);
        return LayuiPageFactory.createPageInfo(page);
	}

	@Override
	public StorageOutResult getPrintstorageOut(StorageOutParam param) {
		return this.baseMapper.getPrintstorageOut(param);
	}

	@Override
	public StorageOutResult findBySpecs(StorageOutParam param) {
		return this.baseMapper.findBySpecs(param);
	}

	@Override
	public List<StorageOutResult> findListByMakeSpec(StorageOutParam param) {
		return this.baseMapper.findListByMakeSpec(param);
	}

	@Override
	public List<StorageOutResult> findPageBySpecWorkNew(StorageOutParam param, String condition,
			Long deptId,Long operateId) {
		return this.baseMapper.findPageBySpecWorkNew(param,condition,deptId, operateId);
	}

	@Override
	public List<StorageOutResult> findPageByGetApp2(StorageOutParam sop, Long deptId) {
		return this.baseMapper.findPageByGetApp2(sop,deptId);
	}

	@Override
	public List<StorageOutResult> findPageBySpecWorkNewexamin(StorageOutParam storageOutParam, String condition,
			Long deptId,Long operateId) {
		return this.baseMapper.findPageBySpecWorkNewexamin(storageOutParam,condition,deptId, operateId);
	}

	@Override
	public List<StorageOutResult> findPageByGetAppWorkexamin(StorageOutParam p, Long deptId,Long operateId) {
		return this.baseMapper.findPageByGetAppWorkexamin(p,deptId,operateId);
	}

	@Override
	public List<StorageOutResult> findListByStrs(StorageOutParam param, String[] strs) {
		return this.baseMapper.findListByStrs(param,strs);
	}

    @Override
    public StorageOutResult findByUserAndStorageOutNumber(Long userId, String storageOutNumber) {
        return this.baseMapper.findByUserAndStorageOutNumber(userId,storageOutNumber);
    }

    @Override
    public void updateUserByStorageOutNumber(Long userId, String name ,Date date, String storageOutNumber) {
        this.baseMapper.updateUserByStorageOutNumber(userId, name ,date,storageOutNumber);
    }


}
